#include <glib.h>

gint main(gint argc, gchar **argv)
{
    GString *string1, *string2, *string3;
    char *str = NULL;
    GBytes *bytes = NULL;
    gconstpointer data = NULL;
    gsize size = 0;

    string1 = g_string_new("hello");
    string2 = g_string_new_len("hello", 3);
    string3 = g_string_sized_new(256);

    g_print("string1:%s, len:%d, allocated_len:%d \n", string1->str, (gint)string1->len, (gint)string1->allocated_len);
    g_print("string2:%s, len:%d, allocated_len:%d \n", string2->str, (gint)string2->len, (gint)string2->allocated_len);
    g_print("string3:%s, len:%d, allocated_len:%d \n", string3->str, (gint)string3->len, (gint)string3->allocated_len);

    str = g_string_free(string1, FALSE);
    g_print("str:%s \n", str);
    g_free(str);

    bytes = g_string_free_to_bytes(string2);
    data = g_bytes_get_data(bytes, &size);
    g_print("bytes: %s \n", (gchar *)data);
    g_bytes_unref(bytes);
    
    g_string_free(string3, TRUE);

    return 0;
}